import { isValid, tween, v3 } from "cc";
import { Utils } from "../../framework/utils/Utils";


export class CoinUIMgr{
    private static instance: CoinUIMgr;
    private constructor() { }
    public static getInstance(): CoinUIMgr {
        if (this.instance == null) {
            this.instance = new CoinUIMgr();
        }
        return this.instance;
    }

    //创建金币ui
    createCoinUI(iCount:number) {
        //丢金币
        // let nodeCoin = PoolMgr.getInstance().getNode("NodeCoinUI");
        // if (nodeCoin) {
        //     nodeCoin.position = v3();
        //     nodeCoin.parent = UIMgr.getInstance().getUIById(UIID.UShowILayer3D).node;
        //     nodeCoin.getChildByName("LabCount").getComponent(Label).string = `+${iCount}`;
        //     this.animCoinUI(nodeCoin);
        // }
        // else {
        //     ResourceMgr.getInstance().loadRes("prefabs", "widget/NodeCoinUI", Prefab, (prefab: Prefab) => {
        //         nodeCoin = instantiate(prefab);
        //         nodeCoin.position = v3();
        //         nodeCoin.parent = UIMgr.getInstance().getUIById(UIID.UShowILayer3D).node;
        //         nodeCoin.getChildByName("LabCount").getComponent(Label).string = `+${iCount}`;
        //         this.animCoinUI(nodeCoin);
        //     });   
        // }
    }

    
    //金币UI动画
    animCoinUI(nodeCoin) {
        if (!isValid(nodeCoin)) {
            return;
        }
        tween(nodeCoin)
            .by(1, { position: v3(0,100,0) })
            .call(() => {
                Utils.addToPool(nodeCoin.name, nodeCoin);
            })
            .start();
    }
}